import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {baseDefaultUrl} from './config/config'

Vue.prototype.$http = axios

Vue.use(ElementUI);

Vue.config.productionTip = false

axios.defaults.baseURL = baseDefaultUrl

axios.interceptors.request.use(function (config){
 const token = window.sessionStorage.getItem('token')
  if (token) {
    config.headers.Authorization = token
  }
  return config;
},error=>{
  console.log('发送错误：',error);
  return Promise.reject(error);
});

//响应
axios.interceptors.response.use(function (resp){
  if(resp.data.code === 0){
    ElementUI.Message.error(resp.data.message)
    return Promise.reject(error);
  }
  if(resp.data.code === 1){
    return resp.data.data;
  }

},error=>{
  console.log("返回错误：",error);
  ElementUI.Message.error(error.message)
  return Promise.reject(error);
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
